//
//  ExtFeeCaculator.js
//  SugLisSystem
//  职业加费
//  Created by Mr.Right on 2013-04-05.
//  Copyright 2013 Mr.Right. All rights reserved.
//

var db = require('untils/DB');
// 加费单位，每1000元
var unitFlag = 1000.00;
// 标准费率
var stdFlag = "STD";
// 拒保标识
var refuseFlag = "拒保";

/**
 * 返回是否拒保
 *
 * @param riskCode
 * @param occupationCode
 * @return true 为拒保
 */
function checkRefuse(riskCode, occupationCode) {
	return refuseFlag == getOccupationTypeByCode(riskCode, occupationCode);
}

exports.checkRefuse = checkRefuse;

/**
 * 通过职业代码，险种获取职级以及相关信息 【保险公司不同，加费逻辑不一样，需要客户化】
 *
 * @param riskCode
 * @param occupationCode
 * @return
 */
function getOccupationTypeByCode(riskCode, occupationCode) {
	var LMRiskAppDB = new dB('LMRiskApp');
	LMRiskAppDB['riskcode'] = riskCode;
	LMRiskAppDB.getInfo();
	var riskType = LMRiskAppDB['risktype'];

	var LDOccupationDB = new dB('LDOccupation');
	LDOccupationDB['occupationcode'] = occupationCode;
	LDOccupationDB.getInfo();

	var occupationType = stdFlag;
	if (riskType == 'L') {
		occupationType = LDOccupationDB['liferate'];
	} else if (riskType == 'W') {
		occupationType = LDOccupationDB['wprate'];
	} else if (riskType == 'H') {
		occupationType = LDOccupationDB['hirate'];
		if (refuseFlag != occupationType) {
			occupationType = stdFlag;
		}
	} else if (riskType == 'A') {
		occupationType = LDOccupationDB['parate'].split('/')[0];
		if (refuseFlag != occupationType) {
			occupationType = stdFlag;
		}
	}

	return occupationType;
}

exports.getOccupationTypeByCode = getOccupationTypeByCode; 